{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 决策树解决分类问题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用scikit-learn中的决策树进行分类"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 准备数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn import datasets\n",
    "\n",
    "iris = datasets.load_iris()\n",
    "X = iris.data[:, 2:]\n",
    "y = iris.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAGg9JREFUeJzt3X2QXXV9x/H3d+9umhgoGc1CYhIMSsBRHgzs8GAcZWqNAilJrRGY+hCHSsdKhYnaESdTU4wjHTpoKlQagQKVRkiIIRIspVKrloa6CUgqT2JAEwhkAQkmhpLsfvvHvUl2756b+zv3nL3n4X5eM5nsPfu753wvTL579pzP73fM3RERkXLpyroAERFJn5q7iEgJqbmLiJSQmruISAmpuYuIlJCau4hICam5i4iUkJq7iEgJqbmLiJRQd1YHnjx5ss+cOTOrw4uIFNLGjRtfcPfeZuMya+4zZ86kv78/q8OLiBSSmf0qZJwuy4iIlJCau4hICam5i4iUkJq7iEgJqbmLiJSQmruISAmpuYuIlFDTnLuZzQBuAaYAQ8AKd19eN+Ys4E7gqdqmNe5+RbqlikjRrd+ynuWblvPc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KmV2W6jGKdlnGzN4N7AJucfcTsq4nCTObCkx1901mdjiwEVjg7o9kXFpstYXiJrr7LjPrAX4CXOruGzIurWVmthjoA37f3edlXU+rzOxpoM/dC58LN7ObgR+7+/W1SZWvc/eXs64ridrKu88Ap7t7krk/IxTuzN3df0TE0gZF5O7b3X1T7evfAo8yelG2QvCqXbWXPbU/xTpzGMbMpgPnAtdnXYtUmdnvA+8GbgBw99eK3thr3gv8Ms3GDgVs7mVlZjOpzvB9INtKWle7jPEQsAO4190L+1mozsj+K2Ao60JS4MC/mdlGM7s462ISeDMwAPxT7XLZ9WY2MeuiUnABsDLtnaq554CZHQbcAVzm7q9kXU+r3H3Q3d9BdXG508yskJfNzGwesMPdN2ZdS0rmuPspVB+48+napc0i6gZOAb7p7rOB3cAXsi0pmdqlpfOAVWnvW809Y7Xr03cAt7r7mqzrSUPtV+UfAh/IuJRWzQHOq12r/g7wB2b27WxLap27P1v7ewfwXaoP4CmibcC2Yb8Rrqba7IvsbGCTuz+f9o7V3DNUuwl5A/Cou1+ddT1JmFmvmU2qfT0B+EPgsWyrao27X+7u0919JtVfme9z949kXFZLzGxi7WY9tUsYc4FCJs3c/Tlgq5kdX9v0XqBw4YM6FzIGl2Sg+mtOoZjZSuAsYLKZbQO+5O43ZFtVy+YAHwU2165VA3zR3e/OsKZWTQVurt357wJud/dCRwhL4ijgu7WnXnYD/+Lu/5ptSYn8JXBr7XLGFuATGdfTMjN7HfA+4M/HZP9Fi0KKiEhzuiwjIlJCau4iIiWk5i4iUkJq7iIiJaTmLiJSQmruIiIlpOYuIlJCau4iIiX0/+4IPwXlrZZrAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X[y == 0, 0], X[y == 0, 1])\n",
    "plt.scatter(X[y == 1, 0], X[y == 1, 1])\n",
    "plt.scatter(X[y == 2, 0], X[y == 2, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 绘制决策区域\n",
    "def plot_decision_boundary(model, axis):\n",
    "    x0, x1 = np.meshgrid(\n",
    "        np.linspace(axis[0], axis[1], int((axis[1] - axis[0]) * 100)).reshape(-1, 1),\n",
    "        np.linspace(axis[2], axis[3], int((axis[3] - axis[2]) * 100)).reshape(-1, 1)\n",
    "    )\n",
    "    \n",
    "    X_new = np.c_[x0.ravel(), x1.ravel()]\n",
    "    \n",
    "    y_predict = model.predict(X_new)\n",
    "    zz = y_predict.reshape(x0.shape)\n",
    "    \n",
    "    from matplotlib.colors import ListedColormap\n",
    "    custom_cmap = ListedColormap(['#FFCCCC', '#FFFF99', '#CCCCFF'])\n",
    "    plt.contourf(x0, x1, zz, linewidth=5, cmap=custom_cmap)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用信息熵作为分类标准"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(class_weight=None, criterion='entropy', max_depth=2,\n",
       "            max_features=None, max_leaf_nodes=None,\n",
       "            min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "            min_samples_leaf=1, min_samples_split=2,\n",
       "            min_weight_fraction_leaf=0.0, presort=False, random_state=None,\n",
       "            splitter='best')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.tree import DecisionTreeClassifier\n",
    "\n",
    "dt_clf = DecisionTreeClassifier(max_depth=2, criterion=\"entropy\")\n",
    "dt_clf.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\CandyWall\\Anaconda3\\lib\\site-packages\\matplotlib\\contour.py:1000: UserWarning: The following kwargs were not used by contour: 'linewidth'\n",
      "  s)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAHAxJREFUeJzt3X2QXXWd5/H3tzsNIU+kR1IkEyKBgmEmsijpHiRmS1nRHTBZYRRGrNUFa6pCTelsqN11a3ApzbBUOVPs6qRGa9wssIQMiwhEJsPDqDOo6PCg3RFQjBQsD0NCEgJ00nkgJN393T/u7e7bp8/t+7v3nnvPw/28qrrs87u/e+6XWPnm9O98+nfM3RERkWLpSrsAERFJnpq7iEgBqbmLiBSQmruISAGpuYuIFJCau4hIAdVs7mY228x+ZmZPm9mzZvbnMXNONLO7zewFM3vSzJa3olgREQkTcuX+DvBhd38v8D7gEjO7MDLnj4Ehdz8L+Drwl8mWKSIi9ajZ3L3kUPmwp/wV/c2ny4DN5e/vBS42M0usShERqcuskElm1g0MAmcB33T3JyNTlgKvArj7iJkdAN4FvBE5zzpgHcDck07q+93ly5sqXupzhDlplyAiTdqxY/ANd19Ua15Qc3f3UeB9ZrYQ+K6Znevuv6qYEneVPm1fA3ffBGwC6F+xwge2bAn5eEnIIH1plyAiTervt1dC5tWVlnH3/cCPgEsiL+0ElgGY2SzgZOCtes4tIiLJCUnLLCpfsWNmJwEfAX4TmbYNuLr8/RXAI64dyUREUhOyLLME2Fxed+8CvuPuD5jZjcCAu28DbgW2mNkLlK7Yr2pZxSIiUlPN5u7uzwDnx4x/ueL7o8CVyZYmIiKN0m+oiogUkJq7iEgBqbmLiBSQmruISAGpuYuIFJCau4hIAam5i4gUkJq7iEgBqbmLiBSQmruISAGpuYuIFJCau4hIAam5i4gUkJq7iEgBqbmLiBSQmruISAGpuYu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66mJmc4CPAtemXkvRopAiIqJlGRGRQlJzFxEpIDV3EZECUnMXESkgNXcRkQJScxcRKSA1dxGRAvr/PtrbEukaagMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(dt_clf, axis=[0.5, 7.5, 0, 3])\n",
    "plt.scatter(X[y == 0, 0], X[y == 0, 1])\n",
    "plt.scatter(X[y == 1, 0], X[y == 1, 1])\n",
    "plt.scatter(X[y == 2, 0], X[y == 2, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用基尼系数作为分类标准"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=2,\n",
       "            max_features=None, max_leaf_nodes=None,\n",
       "            min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "            min_samples_leaf=1, min_samples_split=2,\n",
       "            min_weight_fraction_leaf=0.0, presort=False, random_state=None,\n",
       "            splitter='best')"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt_clf = DecisionTreeClassifier(max_depth=2, criterion=\"gini\")\n",
    "dt_clf.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\CandyWall\\Anaconda3\\lib\\site-packages\\matplotlib\\contour.py:1000: UserWarning: The following kwargs were not used by contour: 'linewidth'\n",
      "  s)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x234df86dd30>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image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xGRAvr/PtrbEukaagMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(dt_clf, axis=[0.5, 7.5, 0, 3])\n",
    "plt.scatter(X[y == 0, 0], X[y == 0, 1])\n",
    "plt.scatter(X[y == 1, 0], X[y == 1, 1])\n",
    "plt.scatter(X[y == 2, 0], X[y == 2, 1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 信息熵"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 表达式"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "熵在信息论中代表 随机变量的不确定度的度量\n",
    "\n",
    "$H=-\\sum\\limits_{i=1}^{k}p_ilog(p_i)$\n",
    "\n",
    "当k=2时\n",
    "\n",
    "$H=-xlog(x)-(1-x)log(1-x)$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def entropy(p):\n",
    "    return -p * np.log(p) - (1-p) * np.log(1 - p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.linspace(0.01, 0.99, 200)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "函数图像为如下"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xd8lfXd//HX52QnZEEGIQkkgQQIICtsE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cr901AuoikikggHSdMl540Zilwe+fH1wGfm84zEh6sx+PuXJ74Gx3F7g3rr9DDcRtjqowxMcaYFGNMCh3nGmYbY7Ktiesw9vw9f4+Ok+iISAwdyzQHXZrS8ew57qPAhQAiMpyOci9zaUprLAVu67xqZjJQZYwp6tVXtPos8inOGu+n46z6I53vPUbHf9TQ8cP+J5ALbATSrM7souP+FCgBtnX+WWp1Zlcc90ljv8ALrpax8+ctwJPAbmAnMNfqzC467kxgDR1X0mwDLrE6s4OOezFQBLTQMUu/E7gHuKfLz3th57+XnY74e653qCqllBdyt2UZpZRSDqDlrpRSXkjLXSmlvJCWu1JKeSEtd6WU8kJa7kop5YW03JVSygtpuSullBf6f2LSvo9kyHKxAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(x, entropy(x))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用信息熵寻找最优决策树划分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def split(X, y, d, value):\n",
    "    index_a = (X[:, d] <= value)\n",
    "    index_b = (X[:, d] >= value)\n",
    "    return X[index_a], X[index_b], y[index_a], y[index_b]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import Counter\n",
    "from math import log\n",
    "\n",
    "def entropy(y):\n",
    "    counter = Counter(y)\n",
    "    res = 0.0\n",
    "    \n",
    "    for num in counter.values():\n",
    "        p = num / len(y)\n",
    "        res += -p * log(p)\n",
    "    return res\n",
    "\n",
    "def try_split(X, y):\n",
    "    best_entropy = float('inf')\n",
    "    best_d, best_v = -1, -1\n",
    "    for d in range(X.shape[1]):\n",
    "        sorted_indexes = np.argsort(X[:, d])\n",
    "        for i in range(1, len(X)):\n",
    "            if X[sorted_indexes[i - 1], d] != X[sorted_indexes[i], d]:\n",
    "                v = (X[sorted_indexes[i - 1], d] + X[sorted_indexes[i], d]) / 2\n",
    "                X_l, X_r, y_l, y_r = split(X, y, d, v)\n",
    "                e = entropy(y_l) + entropy(y_r)\n",
    "                if e < best_entropy:\n",
    "                    best_entropy, best_d, best_v = e, d, v\n",
    "    return best_entropy, best_d, best_v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "best_entropy 0.6931471805599453\n",
      "best_d 0\n",
      "best_v 2.45\n"
     ]
    }
   ],
   "source": [
    "best_entropy, best_d, best_v = try_split(X, y)\n",
    "print(\"best_entropy\", best_entropy)\n",
    "print(\"best_d\", best_d)\n",
    "print(\"best_v\", best_v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "x1_l, X1_r, y1_l, y1_r = split(X, y, best_d, best_v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entropy(y1_l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6931471805599453"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entropy(y1_r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "best_entropy2 0.4132278899361904\n",
      "best_d2 1\n",
      "best_v2 1.75\n"
     ]
    }
   ],
   "source": [
    "best_entropy2, best_d2, best_v2 = try_split(X1_r, y1_r)\n",
    "print(\"best_entropy2\", best_entropy2)\n",
    "print(\"best_d2\", best_d2)\n",
    "print(\"best_v2\", best_v2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "x2_l, X2_r, y2_l, y2_r = split(X1_r, y1_r, best_d2, best_v2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.30849545083110386"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entropy(y2_l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.10473243910508653"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entropy(y2_r)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 基尼系数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 表达式"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "基尼系数跟信息熵一样，也可以表示随机变量的不确定度\n",
    "\n",
    "$G=1-\\sum\\limits_{i=1}^kp_i^2$\n",
    "\n",
    "当k=2时\n",
    "\n",
    "$G=1-x^2-(1-x)^2=-2x^2+2x$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    " def G(x):\n",
    "    return -2 * x ** 2 + 2 * x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.linspace(0.01, 0.99, 200)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "函数曲线如下："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgI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sndn9uz3HGAJgDFmLRBEy9orns6uDjgdrlbuPy5SJiIBtJwwXXrCNv9apAzsXKTMDXS4362HJ16mpdg94fgrdLDfxpgKY0ykMSbZGJNMy7mGGcaYLGviOow93+cf03ISHRGJpOUwTa5TUzqePfu9H5gEICIDaCl3b1gffClwY+usmTFAhTHmwFm9otVnkU9y1ngPLWfVf9P6ucdp+U8NLV/s94Ec4AcgxerMTtrvr4BDwObWP0utzuyM/T5h2xV4wGwZO7/eAjwLZAPbgJlWZ3bSfqcDq2mZSbMZmGJ1Zgft9yLgANBIyyh9DnA7cHubr/e81n+XbY74PtcrVJVSygO52mEZpZRSDqDlrpRSHkjLXSmlPJCWu1JKeSAtd6WU8kBa7kop5YG03JVSygNpuSullAf6f/AzfbKFaMEZAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(x, G(x))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用基尼系数寻找最优决策树划分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "def split(X, y, d, value):\n",
    "    index_a = (X[:, d] <= value)\n",
    "    index_b = (X[:, d] >= value)\n",
    "    return X[index_a], X[index_b], y[index_a], y[index_b]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import Counter\n",
    "from math import log\n",
    "\n",
    "def gini(y):\n",
    "    counter = Counter(y)\n",
    "    res = 1.0\n",
    "    \n",
    "    for num in counter.values():\n",
    "        p = num / len(y)\n",
    "        res -= p ** 2\n",
    "    return res\n",
    "\n",
    "def try_split(X, y):\n",
    "    best_g = float('inf')\n",
    "    best_d, best_v = -1, -1\n",
    "    for d in range(X.shape[1]):\n",
    "        sorted_indexes = np.argsort(X[:, d])\n",
    "        for i in range(1, len(X)):\n",
    "            if X[sorted_indexes[i - 1], d] != X[sorted_indexes[i], d]:\n",
    "                v = (X[sorted_indexes[i - 1], d] + X[sorted_indexes[i], d]) / 2\n",
    "                X_l, X_r, y_l, y_r = split(X, y, d, v)\n",
    "                g = gini(y_l) + gini(y_r)\n",
    "                if g < best_g:\n",
    "                    best_g, best_d, best_v = g, d, v\n",
    "    return best_g, best_d, best_v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "best_g 0.5\n",
      "best_d 0\n",
      "best_v 2.45\n"
     ]
    }
   ],
   "source": [
    "best_g, best_d, best_v = try_split(X, y)\n",
    "print(\"best_g\", best_g)\n",
    "print(\"best_d\", best_d)\n",
    "print(\"best_v\", best_v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "x1_l, X1_r, y1_l, y1_r = split(X, y, best_d, best_v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entropy(y1_l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6931471805599453"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entropy(y1_r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "best_g2 0.2105714900645938\n",
      "best_d2 1\n",
      "best_v2 1.75\n"
     ]
    }
   ],
   "source": [
    "best_g2, best_d2, best_v2 = try_split(X1_r, y1_r)\n",
    "print(\"best_g2\", best_g2)\n",
    "print(\"best_d2\", best_d2)\n",
    "print(\"best_v2\", best_v2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "x2_l, X2_r, y2_l, y2_r = split(X1_r, y1_r, best_d2, best_v2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.1680384087791495"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gini(y2_l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.04253308128544431"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gini(y2_r)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## CART和决策树中的超参数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 准备数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn import datasets\n",
    "\n",
    "X, y = datasets.make_moons(noise=0.25, random_state=666)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAD8CAYAAACfF6SlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAHU1JREFUeJzt3X2MXFd5x/HvE8eQpa28CTYkWXvrpE0Dea1hFV5cVWlcGhKaxA0hTfiDUBFZtI1oUymqUSVjRariNFKjpqFFhiKCVEJMAGOKkdvGICrapFmT2E4IBhOg7DoiIRC3CJf65ekfcwfPzt6Z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1BbfvQeA54GjyGnwP8F7gvcnjBnwwaf9++lTLldS+2zqu36PAm4tsX9KG36CVwtkHPJn8uzqW65ixfbmuo2b4iog0UKXTPiIiMhoFfxGRBlLwFxFpIAV/EZEGUvAXEWkgBX8RkQZS8BcRaSAFfxGRBvp/RNEY8SiTfQkAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X[y == 0, 0], X[y == 0, 1])\n",
    "plt.scatter(X[y == 1, 0], X[y == 1, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用决策树训练模型并进行分类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None,\n",
       "            max_features=None, max_leaf_nodes=None,\n",
       "            min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "            min_samples_leaf=1, min_samples_split=2,\n",
       "            min_weight_fraction_leaf=0.0, presort=False, random_state=None,\n",
       "            splitter='best')"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt_clf = DecisionTreeClassifier()\n",
    "dt_clf.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\CandyWall\\Anaconda3\\lib\\site-packages\\matplotlib\\contour.py:1000: UserWarning: The following kwargs were not used by contour: 'linewidth'\n",
      "  s)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF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nlmPji8yav7H1CLvIeA3wMPR9tOBh6LHZ1Kr9HgSeJpaCie4dvpblQg/p3a1nUc7VwLfB34R/f3OaPsG4J7o8fuBp6Lj+RTw6Qzbd9zxAW4Frogenwh8G3gO+AlwZk6fy3btvC36LD4JPAqsy6GN3wBeBI5En81PAzcAN0S/N2o3qfoWnlP6AAAAWUlEQVRl9D63rOLLuZ03NhzLHwHvz6GNF1NL/+wGnoj+fCi045mwnR0fTy1dISIiQMFSRiIi0j8KCCIiAiggiIhIRAFBREQABQQREYkoIIiICKCAICIikf8PP02Jo+3yWUQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(dt_clf, axis=[-1.5, 2.5, -1.0, 1.5])\n",
    "plt.scatter(X[y == 0, 0], X[y == 0, 1])\n",
    "plt.scatter(X[y == 1, 0], X[y == 1, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "从上面绘制的决策边界可以看出，训练的决策树分类模型已经过拟合了，下面将通过调节决策树的参数来解决过拟合的问题。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 调节参数解决过拟合问题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 设置决策树的最大深度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=2,\n",
       "            max_features=None, max_leaf_nodes=None,\n",
       "            min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "            min_samples_leaf=1, min_samples_split=2,\n",
       "            min_weight_fraction_leaf=0.0, presort=False, random_state=None,\n",
       "            splitter='best')"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt_clf2 = DecisionTreeClassifier(max_depth=2)\n",
    "dt_clf2.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\CandyWall\\Anaconda3\\lib\\site-packages\\matplotlib\\contour.py:1000: UserWarning: The following kwargs were not used by contour: 'linewidth'\n",
      "  s)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAHvZJREFUeJzt3X+MXeV95/H31xNsZpJQTzCuYcYMULFM6eBN8IgmASGycXbT0AVnkxBStCFSkOXNIrZVFjVRJbdraUWyqKstS7fUoagJokkcsuuaDRWNQyJaNiTYKRgDJiEkI98xiYE4UDQT/xh/9497rpm5vj/Ovefcc55zzuclWb5z5njO43PvPN9zvs/3eY65OyIiIsvyboCIiIRBAUFERAAFBBERiSggiIgIoIAgIiIRBQQREQFSCghmdo+ZHTKzfW2+f5WZvWpmT0R/tqRxXBERSc+bUvo5fw3cCXypwz7/4O6/m9LxREQkZancIbj7I8Av0vhZIiKSj7TuEOJ4l5k9CRwE/rO7P928g5ltAjYBvHl4eP3keedl2DwRiWuOkbybIG08++yel939rH7+bVYB4QfAhLu/bmYfAHYAFzbv5O7bgG0A0xdf7LvvvTej5olIL/awPu8mSBvT0zbT77/NpMrI3V9z99ej1w8Cp5nZqiyOLSIi8WQSEMxsjZlZ9Pqy6LivZHFsERGJJ5WUkZl9GbgKWGVmNeCPgdMA3P0u4MPAfzCz48A8cL1rmVURkaCkEhDc/WNdvn8n9bJUEREJlGYqi4gIkG3ZqRTUjpk5bt/3OgfnTnDOyDJunXoLGydUdihSNg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jfwVHQ+nwI+mWH7Tjk/wFbgmuj16cDXgOeB7wMX5PS57NbO26LP4pPAt4HJHNr4ZeBF4Fj02fwksBnYHH3fqD+k6sfR+9y2ii/ndt686Fw+Brw7hzZeQT39sxd4IvrzgdDOZ8x29nw+tXSFiIgABUsZiYjI4CggiIgIoIAgIiIRBQQREQEUEEREJKKAICIigAKCiIhE/j9RbSHdBotoIwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(dt_clf2, axis=[-1.5, 2.5, -1.0, 1.5])\n",
    "plt.scatter(X[y == 0, 0], X[y == 0, 1])\n",
    "plt.scatter(X[y == 1, 0], X[y == 1, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 设置每一个分类中元素的最少个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None,\n",
       "            max_features=None, max_leaf_nodes=None,\n",
       "            min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "            min_samples_leaf=1, min_samples_split=10,\n",
       "            min_weight_fraction_leaf=0.0, presort=False, random_state=None,\n",
       "            splitter='best')"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt_clf3 = DecisionTreeClassifier(min_samples_split=10)\n",
    "dt_clf3.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\CandyWall\\Anaconda3\\lib\\site-packages\\matplotlib\\contour.py:1000: UserWarning: The following kwargs were not used by contour: 'linewidth'\n",
      "  s)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVB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vvYlbs/BPy2wy7XAF/ymh8Bq83s7Gxa95oY7cyduz/r7j+NXv8jtcrIsabdcj+fMdvZs2ACQg8c+LaZ7YuWughRq+U6Er9ZPfodd38Wah8eYG2b/U43s71m9iMzyypoxDk/p/bxWunyi8CZmbSuRRsi7d7H90epg/vMbH2L7+cthM9jXG83s0fN7O/N7PfybEiUpnwr8OOmbwV1Pju0E3o8n5k+DyGFZTAALnf3Q2a2FviOmR2M7jxSk+VyHUl0amcPP+bc6HxeADxoZgfc/RfptLCtOOcnk3PYRZw2fBP4irsfM7Nt1Ho1/3zgLetNCOcyjp8CE+7+spm9B9gFXJhHQ8zsDcA3gD9295eav93in+RyPru0s+fzmWlA8OTLYODuh6K/D5vZ/6LWrU81IKTQzkyW6+jUTjP7jZmd7e7PRt3Zw21+Rv18Pm1m36d2pzHogBDn/NT3mTWz1wFvIvt0Q9d2uvuRhi8/D3w2g3b1qhDLxzRe0Nz9fjP7b2a2xt0zXVDOzE6jdpG9193/Z4tdgjif3drZz/ksVMrIzF5vZm+svwb+kNozGUITwnIdu4Ebotc3AMt6NmY2amarotdrgMvJZlnyOOensf0fAB70aKQsQ13b2ZQ7vppaLjc0u4GPRtUxbwNerKcTQ2Jm6+rjRGZ2GbXr05HO/yr1NhjwN8AT7v6f2+yW+/mM086+zmfWo+MdRs3fRy3yHgN+AzwQbT8HuD96fQG1So9HgceopXCCa6e/VonwM2p323m080zgu8DPo7/fHG2fAu6OXr8DOBCdzwPAxzNs37LzA9wKXB29Ph34OvAU8BPggpw+l93aeVv0WXwU+B6wIYc2fgV4FjgRfTY/DmwDtkXfN2oPqfpF9D63reLLuZ03NZzLHwHvyKGNV1BL/+wHHon+vCe08xmznT2fTy1dISIiQMFSRiIiMjgKCCIiAiggiIhIRAFBREQABQQREYkoIIiICKCAICIikf8PaExPJkTTAaQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(dt_clf3, axis=[-1.5, 2.5, -1.0, 1.5])\n",
    "plt.scatter(X[y == 0, 0], X[y == 0, 1])\n",
    "plt.scatter(X[y == 1, 0], X[y == 1, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 设置决策树的叶子节点最少的样本数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None,\n",
       "            max_features=None, max_leaf_nodes=None,\n",
       "            min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "            min_samples_leaf=6, min_samples_split=2,\n",
       "            min_weight_fraction_leaf=0.0, presort=False, random_state=None,\n",
       "            splitter='best')"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt_clf4 = DecisionTreeClassifier(min_samples_leaf=6)\n",
    "dt_clf4.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\CandyWall\\Anaconda3\\lib\\site-packages\\matplotlib\\contour.py:1000: UserWarning: The following kwargs were not used by contour: 'linewidth'\n",
      "  s)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAH31JREFUeJzt3X+MHOWd5/H31xM8zCRhmdh4DTNmgBNnLztwCbbYJESIXJxVNtwBuSSEBF2IFOT15RB30R5KopW8K6QTyUV70SJ2DzlstAkiP5xw55iDFYk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Td6/jBKHXwHTNb0+L5vIXwfozrHWb2hJn9g5n9YZ4NidKUbwN+3PRUUOezQzuhx/OZ6f0QUlgGA+Bydz9oZquA75vZ/uibR2qyXK4jiU7t7OHXnBudzwuAh81sn7v/Ip0WthXn/GRyDruI04b7gW+4+1Ez20ytV/OvB96y3oRwLuP4KTDp7q+Y2fuB7cCFeTTEzN4E3Af8Z3d/ufnpFv8kl/PZpZ09n89MA4InXwYDdz8Y/X3IzP4XtW59qgEhhXZmslxHp3aa2W/M7Gx3fz7qzh5q8zvq5/M5M/shtW8agw4Icc5PfZ9ZM3sD8Htkn27o2k53P9Lw45eBL2TQrl4VYvmYxguauz9oZn9rZivdPdMF5czsNGoX2Xvd/X+22CWI89mtnf2cz0KljMzsjWb25vpj4I+p3ZMhNCEs17EDuDF6fCNwSs/GzMbMbDh6vBK4nGyWJY9zfhrb/yHgYY9GyjLUtZ1NueOrqeVyQ7MD+HhUHfN24KV6OjEkZra6Pk5kZpdRuz4d6fyvUm+DAX8HPO3u/73Nbrmfzzjt7Ot8Zj063mHU/APUIu9R4DfAQ9H2c4AHo8cXUKv0eAJ4kloKJ7h2+uuVCD+j9m07j3auAH4A/Dz6+y3R9g3A3dHjdwL7ovO5D/hkhu075fwAtwFXR49PB74NPAv8BLggp/dlt3beHr0XnwAeAdbl0MZvAM8Dx6P35ieBzcDm6HmjdpOqX0Svc9sqvpzbeXPDufwR8M4c2vguaumfvcDj0Z/3h3Y+Y7az5/OppStERAQoWMpIREQGRwFBREQABQQREYkoIIiICKCAICIiEQUEEREBFBBERCTy/wE1Vk1NjFLDeQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(dt_clf4, axis=[-1.5, 2.5, -1.0, 1.5])\n",
    "plt.scatter(X[y == 0, 0], X[y == 0, 1])\n",
    "plt.scatter(X[y == 1, 0], X[y == 1, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 决策树解决回归问题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 准备数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "boston = datasets.load_boston()\n",
    "\n",
    "X = boston.data\n",
    "y = boston.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=666)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用scikit-learn中的决策树回归器处理回归问题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeRegressor(criterion='mse', max_depth=None, max_features=None,\n",
       "           max_leaf_nodes=None, min_impurity_decrease=0.0,\n",
       "           min_impurity_split=None, min_samples_leaf=1,\n",
       "           min_samples_split=2, min_weight_fraction_leaf=0.0,\n",
       "           presort=False, random_state=None, splitter='best')"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.tree import DecisionTreeRegressor\n",
    "\n",
    "dt_reg = DecisionTreeRegressor()\n",
    "dt_reg.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6016452616895374"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt_reg.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt_reg.score(X_train, y_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以看出使用默认的参数训练决策树模型处理回归问题，在训练数据集上的准确率表现得非常好，可是在测试数据集上的表现却不好，这显然是一种过拟合的表现。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 调节参数解决过拟合问题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 决策树的局限性"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 缺点1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "分类的决策边界是横平竖直的，泛化能力比较差。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 缺点2：分类结果容易受到某个样本的干扰"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "iris = datasets.load_iris()\n",
    "X = iris.data[:, 2:]\n",
    "y = iris.target"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "删除索引为138的样本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_new = np.delete(X, 138, axis=0)\n",
    "y_new = np.delete(y, 138)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(149, 2)"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_new.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(149,)"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_new.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(class_weight=None, criterion='entropy', max_depth=2,\n",
       "            max_features=None, max_leaf_nodes=None,\n",
       "            min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "            min_samples_leaf=1, min_samples_split=2,\n",
       "            min_weight_fraction_leaf=0.0, presort=False, random_state=None,\n",
       "            splitter='best')"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tree_clf = DecisionTreeClassifier(max_depth=2, criterion=\"entropy\")\n",
    "tree_clf.fit(X_new, y_new)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\CandyWall\\Anaconda3\\lib\\site-packages\\matplotlib\\contour.py:1000: UserWarning: The following kwargs were not used by contour: 'linewidth'\n",
      "  s)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAG9RJREFUeJzt3X2QXXWd5/H3tzsNIQ+QjKRIJkQCBcsusijJHSRmS1nRHTBZYRVGrNUFa6piTelsqN11a1BKMyxVzhS7OqnVGjcLLIFhEYHIZHhYdQcVHR60OwKKkYLlYUhIQoA8h5B093f/uLe7b58+t+/v3HvuPQ/386rqss/v/u65X2Llm9O/8+nfMXdHRETKpS/rAkREJH1q7iIiJaTmLiJSQmruIiIlpOYuIlJCau4iIiXUtLmb2Uwz+4WZPW1mz5rZn8fMOd7M7jazF8zsSTNb2oliRUQkTMiV+zvAh939vcD7gEvM7MLInD8G9rj7mcA3gb9Mt0wREUmiaXP3qoO1w4HaV/Q3ny4DNta+vxe42MwstSpFRCSRGSGT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6gtUxbFDGAZ8Nfufj5wCPizbEtKrrac9HHgnizrUHPPodp69X3Ane6+Ket6WlH7cfonwCUZl5LESuDjtXXr7wIfNrO/ybakZNz9tdr/vg58n+qurkWxDdhW99PevVSbfdFcCmxx911ZFqHmnjO1m5K3AFvd/RtZ15OEmS0ws3m1708APgL8Ltuqwrn7de5+qrsvpfpj9SPu/pmMywpmZrNrN+GpLWf8K6AwqTF33wm8amZn14YuBnIfJIjxaTJekoESPmbPzO4CLgJONrNtwNfc/ZZsq0pkJfBZ4Ne1tWuAL7v7QxnWFGoRsLGWFOgDvufuhYsTFtgpwPdrj1KYAfxvd/8/2ZaU2J8Cd9aWNl4EPpdxPYmY2Szgo8DnM6+lbFFIERHRsoyISCmpuYuIlJCau4hICam5i4iUkJq7iEgJqbmLiJSQmruISAn9f3hhzRR+A+h+AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(tree_clf, axis=[0.5, 7.5, 0, 3])\n",
    "plt.scatter(X[y == 0, 0], X[y == 0, 1])\n",
    "plt.scatter(X[y == 1, 0], X[y == 1, 1])\n",
    "plt.scatter(X[y == 2, 0], X[y == 2, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以看到仅仅是删除了索引为138的样本，决策边界就发生了变化，所以某些样本点可能会很大程度影响决策树的分类结果"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "253.458px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
